using UnityEngine;
using UnityEngine.UI;

public class UIWorldLabel : MonoBehaviour
{
	[SerializeField]
	private Text worldText;

	[SerializeField]
	private Text starsProgressText;

	[SerializeField]
	private Text crownsProgressText;

	[SerializeField]
	private Image panelBackground;

	[SerializeField]
	private WorldsColoursList worldsColours;

	private RectTransform listRectTransform;

	private RectTransform parentRectTransfrom;

	private RectTransform thisRectTransform;

	private float initialPosition;

	private bool movementEnabled;

	private float initialAnchor;

	private float maxAnchor;

	public void Initialize(int worldId, int stars, int starsCount, int crowns, int crownsCount)
	{
		worldText.text = LanguageController.instance.GetStringWithNewLinesAndSpaces("LevelPicker_World") + worldId.ToString();
		starsProgressText.text = stars + "/" + starsCount;
		crownsProgressText.text = crowns + "/" + crownsCount;
		panelBackground.color = worldsColours.GetPalette(worldId).worldPanel;
	}

	public void EnableLabelMovement()
	{
		listRectTransform = GetComponentInParent<VerticalLayoutGroup>().GetComponent<RectTransform>();
		parentRectTransfrom = base.transform.parent.GetComponent<RectTransform>();
		thisRectTransform = GetComponent<RectTransform>();
		Vector2 anchoredPosition = thisRectTransform.anchoredPosition;
		initialAnchor = Mathf.Abs(anchoredPosition.y);
		Vector2 sizeDelta = parentRectTransfrom.sizeDelta;
		float num = sizeDelta.y - Mathf.Abs(initialAnchor);
		Vector2 sizeDelta2 = thisRectTransform.sizeDelta;
		maxAnchor = Mathf.Abs(num - sizeDelta2.y) + 2f * initialAnchor;
		Vector2 anchoredPosition2 = parentRectTransfrom.anchoredPosition;
		float num2 = Mathf.Abs(anchoredPosition2.y);
		Vector2 anchoredPosition3 = thisRectTransform.anchoredPosition;
		initialPosition = num2 + Mathf.Abs(anchoredPosition3.y);
		movementEnabled = true;
	}

	private void LateUpdate()
	{
		if (movementEnabled)
		{
			Vector2 anchoredPosition = listRectTransform.anchoredPosition;
			float y = anchoredPosition.y;
			float num = y - initialPosition;
			num += initialAnchor;
			float num2 = Mathf.Clamp(num, initialAnchor, maxAnchor);
			RectTransform rectTransform = thisRectTransform;
			Vector2 anchoredPosition2 = thisRectTransform.anchoredPosition;
			rectTransform.anchoredPosition = new Vector2(anchoredPosition2.x, 0f - num2);
		}
	}
}
